package com.example.myapplication.widget;

import android.os.Bundle;
import android.util.Log;
import android.widget.CheckBox;
import android.widget.CompoundButton;

import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;

import com.example.myapplication.R;

public class CheckBoxActivity extends AppCompatActivity implements CompoundButton.OnCheckedChangeListener {

    private CheckBox customCheckBox;
    private CheckBox systemCheckBox;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        EdgeToEdge.enable(this);
        setContentView(R.layout.activity_check_box);
        ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main), (v, insets) -> {
            Insets systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars());
            v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom);
            return insets;
        });

        customCheckBox = findViewById(R.id.checkbox_custom);
        customCheckBox.setOnCheckedChangeListener(this);

        systemCheckBox = findViewById(R.id.checkbox_system);
        systemCheckBox.setOnCheckedChangeListener(this);
        systemCheckBox.setButtonDrawable(R.drawable.check_state);
    }

    @Override
    public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
        String text = isChecked ? "您勾选了" : "您取消了勾选";
        if (buttonView.getId() == R.id.checkbox_custom) {
            customCheckBox.setText(text);
            Log.d("CheckBoxActivity", customCheckBox.isChecked() ? "被选中" : "没选中");
        } else if (buttonView.getId() == R.id.checkbox_system) {
            systemCheckBox.setText(text);
        }
    }
}